//
//  ActivityTableViewCell.m
//  DaHaiDouBan
//
//  Created by dllo on 15/10/27.
//  Copyright (c) 2015年 Wang Dahai. All rights reserved.
//

#import "ActivityTableViewCell.h"

#import "UIImageView+WebCache.h"

@implementation ActivityTableViewCell
- (void)dealloc
{
    [_big1ImageView release];
    [_titleLabel release];
    [_big2ImageView release];
    [_headImageView release];
    [_timeImageView release];
    [_timeLable release];
    [_addressImageView release];
    [_addressLabel release];
    [_styleImageView release];
    [_styleLabel release];
    [_interestLable release];
    [_joinLable release];
    [super dealloc];
}



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self createSubviews];
    }
    return self;
    
    
}

-(void)createSubviews
{
   
    //大篮筐
    self.big1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake((375 - 355)/2, 10, 355, 168)];
    self.big1ImageView.image = [UIImage imageNamed:@"bg_eventlistcell@2x.png"];
    [self.contentView addSubview:self.big1ImageView];
    [_big1ImageView release];
    //标题标签
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 3, 330, 23)];
    //self.titleLabel.backgroundColor = [UIColor yellowColor];
    [self.big1ImageView addSubview:self.titleLabel];
    [_titleLabel release];
    
    
    
    //小白框
    self.big2ImageView = [[UIImageView alloc] initWithFrame:CGRectMake((355 - 340)/2, 30, 340, 128)];
    self.big2ImageView.image = [UIImage imageNamed:@"bg_share_large@2x.png"];
    [self.big1ImageView addSubview:self.big2ImageView];
    [_big1ImageView release];
    
    
    //图片框
    self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(255, 4, 80, 110)];
    [self.big2ImageView addSubview:self.headImageView];
    [_headImageView release];
    
    //时间
    self.timeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 4, 20, 20)];
    self.timeImageView.image = [UIImage imageNamed:@"icon_date@2x"];
    [self.big2ImageView addSubview:self.timeImageView];
    [_timeImageView release];
    
    
    self.timeLable = [[UILabel alloc] initWithFrame:CGRectMake(30, 4, 220, 21)];
    //self.timeLable.backgroundColor = [UIColor yellowColor];
    [self.big2ImageView addSubview:self.timeLable];
    [_timeLable release];
    
    //地点
    self.addressImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 29, 20, 20)];
    self.addressImageView.image = [UIImage imageNamed:@"icon_spot@2x"];
    [self.big2ImageView addSubview:self.addressImageView];
    [_addressImageView release];
    
    
    self.addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 29, 220, 21)];
   // self.addressLabel.backgroundColor = [UIColor yellowColor];
    [self.big2ImageView addSubview:self.addressLabel];
    [_addressLabel release];
    
    
    //类型
    self.styleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 54, 20, 20)];
    self.styleImageView.image = [UIImage imageNamed:@"icon_catalog@2x"];
    [self.big2ImageView addSubview:self.styleImageView];
    [_styleImageView release];
    
    
    self.styleLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 54, 220, 21)];
    //self.styleLabel.backgroundColor = [UIColor yellowColor];
    [self.big2ImageView addSubview:self.styleLabel];
    [_styleLabel release];
    
    //兴趣
    self.interestLable = [[UILabel alloc] initWithFrame:CGRectMake(15, 90, 110, 20)];
   // self.interestLable.backgroundColor = [UIColor yellowColor];
    [self.big2ImageView addSubview:self.interestLable];
    [_interestLable release];
    //参加
    self.joinLable = [[UILabel alloc] initWithFrame:CGRectMake(140, 90, 110, 20)];
   // self.joinLable.backgroundColor = [UIColor yellowColor];
    [self.big2ImageView addSubview:self.joinLable];
    [_joinLable release];
    
    
}

-(void)setActivity:(Activity *)activity
{
    
    if (_activity != activity) {
        
        [_activity release];
        _activity = [activity retain];
        
    }
    
    self.titleLabel.text = self.activity.title;
    self.addressLabel.text = self.activity.address;
    self.styleLabel.text = self.activity.category_name;
    
    self.interestLable.text = [NSString stringWithFormat:@"感兴趣: %ld",self.activity.wisher_count];
    self.joinLable.text = [NSString stringWithFormat:@"参加: %ld",self.activity.participant_count];
    
    NSString *begin = self.activity.begin_time;
    NSString *end = self.activity.end_time;
    begin = [begin substringFromIndex:5];
    begin = [begin substringToIndex:11];

    end = [end substringFromIndex:5];
    end = [end substringToIndex:11];
    
    self.timeLable.text = [NSString stringWithFormat:@"%@ -- %@",begin,end];
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:_activity.image] placeholderImage:[UIImage imageNamed:@"picholder@2x.png"]];
    
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
